<%@page import="com.exam.dao.StudentDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<jsp:include page="checkAdmin.jsp" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="css/select.css" rel="stylesheet" type="text/css" />
   <link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui.css" />
   <script type="text/javascript" src="js/jquery-2.0.js"></script>
   <script type="text/javascript" src="js/select-ui.min.js"></script>
   <script type="text/javascript" src="js/jquery-ui.js"></script>
   <script type="text/javascript" src="js/jquery.form.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
   		$(".select2").uedSelect({
			width : 167  
		});
   			$('#loading').dialog({
				height:50,
				width:180,
				autoOpen:false,
				modal:true,
				closeOnEscape:false,
				resizable:false,
				
			}).parent().find('.ui-widget-header').hide();
   		
   		

	   	 var options = {
	   	 	url:'student-save.action',
			type:'POST',
		   	beforeSend:function(){
				$('#loading').dialog('open');
				$('#loading').css('background','url(images/loading.gif) no-repeat 20px center').html("数据交互中...");
			},
	        success: function (data,textStatus) {
	        
	           if(data=="success"){
				
				$('#loading').css('background','url(images/success.gif) no-repeat 20px center').html("信息保存成功...");
				setTimeout(function(){
					$('#loading').dialog('close'); 
					$('#loading').css('background','url(images/loading.gif) no-repeat 20px center').html("数据交互中...");
					
				},1000);
				
				//清空表单
				setTimeout(function(){
					$('input[name=stu_id]').val("");
					$('input[name=stu_name]').val("");
				},500);
				
				
			}else{
				$('#loading').css('background','url(images/error.png) no-repeat 20px center').html("信息保存失败...");
				setTimeout(function(){
					$('#loading').dialog('close'); 
					$('#loading').css('background','url(images/loading.gif) no-repeat 20px center').html("数据交互中...");
					
				},1000);
			
			}
	      	}
	     };
    

   			$(".btn").click(function(){
   				//验证表单
   			      var fm = $("#StudnetSaveForm");
   			      
   			      
   			      if($.trim($('input[name=stu_id]').val().length)==0){
   			      	$(".stu_error").html("考生学号不能为空!");
   			      	return false;
   			      }
   			      if(isNaN($.trim($('input[name=stu_id]').val()))){
   			      	$(".stu_error").html("考生学号只能为数值!");
   			      	return false;
   			      }
   			      
   			      if($.trim($('input[name=stu_id]').val().length)>50){
   			      	$(".stu_error").html("考生学号不能超过50字符!");
   			      	return false;
   			      }
   			      if($.trim($('input[name=stu_name]').val().length)==0){
   			      	$(".stu_error").html("考试姓名不能为空!");
   			      	return false;
   			      }
   			      if($.trim($('input[name=stu_name]').val().length)>20){
   			      	$(".stu_error").html("考生姓名不能超过20个字符!");
   			      	return false;
   			      }
   			      
   				 fm.ajaxSubmit(options);
   				 return false;
   			});
   
   		
   		});
   		
   </script>
</head>

<body>
<div id="loading" style="font-size:14px;"></div>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="index.jsp">首页</a></li>
    <li><a href="student-list.action">考生管理</a></li>
    <li><a href="#">添加考生</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    <div class="formtitle"><span>添加考生</span></div>
	   <form id="StudnetSaveForm">
	    <input type="hidden" name="db_user" value="${sessionScope.admin }"/>
	   
	    <ul class="forminfo">
	    <li><p style="color:red" class="stu_error">${fieldErrors.stu_name[0] }</p></li>
	    <li><label>考生学号</label><input type="text" name="stu_id"    class="dfinput" /><i>学号不能超过50个字符</i></li>
	    <li><label>考生姓名</label><input type="text" name="stu_name"  class="dfinput"/><i>姓名不能超过20个字符</i></li>
	    <li><label>所在分组</label>
	    <%
	    	//获取分组 
	    	StudentDao sd = new StudentDao();
	    	request.setAttribute("GroupList", sd.getAllGroup(""));
	     %>
	    <div class="vocation">
	   		 <select class="select2" name="gid">
	    	<s:iterator value="#request.GroupList" status="gb">
	    			<option value="<s:property value="id"/>"><s:property value="gname"/></option>
	    	</s:iterator>
		    
	  	  	</select>
	    </div>	
	    
	    </li>
	    <li><label>&nbsp;</label><input  type="button" class="btn" value="确认保存"/></li>
	    </ul>
	    </form>
    </div>
</body>
</html>
